<template>
    <div>
   <h1>新增科室信息页面</h1>
    </div>
     <table class="table">
          <tbody>
              <tr>
                 <td>科室名称</td>
                  <td>
                    <input type="text" v-model="data.departmentNmae">
                  </td>
              </tr>

               <tr>
                 <td>图片</td>
                  <td>
                    <input type="file" @change="tp">
                    <img style="width:45px;height:45px;" :src="axios.defaults.baseURL+data.departmentImg">
                  </td>
              </tr>

               <tr>
                 <td>成立日期</td>
                  <td>
                    <input type="date" v-model="data.departmentDate">
                  </td>
              </tr>

               <tr>
                 <td></td>
                  <td>
                     <input type="button" value="新增" @click="adds">
                  </td>
              </tr>
          </tbody>
     </table>
</template>

<script setup lang="ts">
 import axios from 'axios';
  import {ref} from 'vue';
  import {useRouter} from 'vue-router';
 
 const router=useRouter();


  const tp=(ed:any)=>{
      let f=ed.target.files[0];
      let fs=new FormData();
      fs.append("file",f);
      axios.post("https://localhost:7170/api/Upload/Up",fs).then(res=>{
         data.value.departmentImg=res.data;

      })
  }
  const data=ref({
     "departmentId": 0,
  "departmentNmae": "",
  "departmentImg": "string",
  "departmentDate": "2025-07-09T12:45:26.934Z"
  })

   const adds=()=>{
     axios.post("https://localhost:7170/api/Department/AddDepartment",data.value).then(res=>{
         if(res.data==-1){
             alert("科室名称不能重复");
              return;
         }else if(res.data>0){
     alert("新增成功");
      router.push("/sh");

         }else{
             alert("新增失败")
         }
     })
   }
</script>

<style scoped>

</style>